﻿using Framework.Core;
using Framework.Startup.Attributes;

namespace Framework.Startup.Test
{
	[DependsOn(typeof(TestApp1Startup))]
	public class TestAppStartup : StartupModule<TestAppStartup>
	{
		public TestAppStartup()
		{
			this.Order = 2;
		}

		public override void ConfigureServices(WebApplicationBuilder webApplicationBuilder)
		{
			// Add services to the container.

			//webApplicationBuilder.Services.AddControllers();
			//// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
			//webApplicationBuilder.Services.AddEndpointsApiExplorer();
		}

		public override void Configure(WebApplication webApplication)
		{
			webApplication.UseHttpsRedirection();

			var summaries = new[]
			{
				"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
			};

			webApplication.MapGet("/weatherforecast", () =>
			{
				var forecast = Enumerable.Range(1, 5).Select(index =>
					new WeatherForecast
					(
						DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
						Random.Shared.Next(-20, 55),
						summaries[Random.Shared.Next(summaries.Length)]
					))
					.ToArray();
				return forecast;
			});

		}
	}

	internal record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
	{
		public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
	}
}
